package io.renren.modules.generator.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.generator.dao.BsnGoutongzhidaoDao;
import io.renren.modules.generator.dao.BsnStudentDao;
import io.renren.modules.generator.entity.BsnGoutongzhidaoEntity;
import io.renren.modules.generator.entity.BsnStudentEntity;
import io.renren.modules.generator.entity.ViewGoutongzhidao;
import io.renren.modules.generator.service.BsnGoutongzhidaoService;


@Service("bsnGoutongzhidaoService")
public class BsnGoutongzhidaoServiceImpl extends ServiceImpl<BsnGoutongzhidaoDao, BsnGoutongzhidaoEntity> implements BsnGoutongzhidaoService {
	
	@Autowired
	private BsnStudentDao studentDao;
	
	@Autowired
	private BsnGoutongzhidaoDao goutongzhidaoDao;
	
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        Page<BsnGoutongzhidaoEntity> page = this.selectPage(
                new Query<BsnGoutongzhidaoEntity>(params).getPage(),
                new EntityWrapper<BsnGoutongzhidaoEntity>()
        );

        return new PageUtils(page);
    }
    
    @Override    
    public PageUtils queryPage(Map<String, Object> params, EntityWrapper<BsnGoutongzhidaoEntity> wrapper) {
        Page<BsnGoutongzhidaoEntity> page = this.selectPage(
                new Query<BsnGoutongzhidaoEntity>(params).getPage(),
                wrapper
        );

        return new PageUtils(page);
    }
    
    @Override 
    public String queryStudentNameByzhidaoId(String id) {
    	List<BsnStudentEntity> retList = studentDao.queryByZhiDaoId(id);
    	String names = "";
    	for (BsnStudentEntity student : retList) {
    		names = names + student.getXingm() +",";
		}
    	if (names.endsWith(",")) {
    		names = names.substring(0, names.length() - 1);
    	}
    	return names;
    }
    
    @Override
    public List<ViewGoutongzhidao> queryPageByStudentId(ArrayList<String> studentIds, Integer page, Integer limit) {
    	Integer start = (page - 1) * limit;     	
    	return goutongzhidaoDao.queryPageByStudentId(studentIds, start, limit);
    }
}
